
/*
 * @Author: jiu yin
 * @Date: 2023-04-27 14:23:19
 * @LastEditTime: 2023-06-08 10:03:38
 * @LastEditors: jiu yin zhen jing
 * @FilePath: \AI admin\src\view\login\index.tsx
 * jiu
 */
import { useState, useEffect } from 'react'
import './index.scss'
import { Input, Button, message, Form } from 'antd';
import { useSelector, useDispatch } from 'react-redux'
import { asyncFn, set } from "@/redux/modules/user"
import { setToken } from '@/utils/auth';

function Login() {

    let [user, setUser] = useState({ userName: "", password: "" })
    const [messageApi, contextHolder] = message.useMessage();
    const dispatch = useDispatch()
    const userInfo = useSelector((state: any) => state.user.userInfo)


    const login = () => {
        console.log(user, '登录');
        if (!user.userName) return messageApi.open({ type: 'error', content: '请输入账号', });
        if (!user.password) return messageApi.open({ type: 'error', content: '请输入密码', });


    }
    useEffect(() => {
        console.log(userInfo);
    }, [userInfo])


    const onFinish = (values: any) => {
        console.log('Success:', values);
        // dispatch(set({ name: '123' }))
        // setToken()
    };

    const onFinishFailed = (errorInfo: any) => {
        console.log('Failed:', errorInfo);
    };



    return (
        <div className='login'>
            <div className='box'>
                <h1>欢迎使用碳宇宙管理系统</h1>

                <Form
                    name="basic"
                    labelCol={{ span: 8 }}
                    wrapperCol={{ span: 16 }}
                    style={{ maxWidth: 600 }}
                    initialValues={{ remember: true }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                    autoComplete="off"
                >
                    <Form.Item
                        name="username"
                        rules={[{ required: true, message: '请输入用户名！' }]}
                    >
                        <Input placeholder='请输入用户名' className='input' />
                    </Form.Item>

                    <Form.Item
                        name="password"
                        rules={[{ required: true, message: '请输入密码！' }]}
                    >
                        <Input.Password placeholder='请输入密码'  className='input' />
                    </Form.Item>

                    <Form.Item wrapperCol={{ offset: 0, span: 0 }}>
                        <Button type="primary" htmlType="submit" className='but'>
                            登录
                        </Button>
                    </Form.Item>
                </Form>

                <p className='footer'>忘记密码请联系管理员</p>

            </div>
            {contextHolder}
        </div>
    )
}

export default Login
